import path from 'path'
import multer from 'koa-multer'
//配置
const storage = multer.diskStorage({
  //文件保存路径
  destination: function (req, file, callback) {
    callback(null, path.join(`${process.cwd()}/src/public/uploads`)) //注意路径必须存在

    // callback(null, 'http://1.116.40.155/resource/uploads')
  },
  //修改文件名称
  filename: function (req, file, callback) {
    const fileFormat = file.originalname.split('.')
    callback(null, `${Date.now()}.${fileFormat[fileFormat.length - 1]}`)
  },
})
//加载配置
const upload = multer({ storage: storage })

export default upload
